<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Class: Client</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

    <h1 class="page-title">Class: Client</h1>

    




<section>

<header>
    
        <h2><span class="attribs"><span class="type-signature"></span></span>
            <span class="ancestors"><a href="Paho.MQTT.html">.MQTT</a>.</span>Client<span class="signature">(host, port, path, clientId)</span><span class="type-signature"></span></h2>
        
    
</header>

<article>
    <div class="container-overview">
    
        

    

    
    <h4 class="name" id="Client"><span class="type-signature"></span>new Client<span class="signature">(host, port, path, clientId)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    The JavaScript application communicates to the server using a <a href="Paho.MQTT.Client.html">Paho.MQTT.Client</a> object.
<p>
Most applications will create just one Client object and then call its connect() method,
however applications can create more than one Client object if they wish.
In this case the combination of host, port and clientId attributes must be different for each Client object.
<p>
The send, subscribe and unsubscribe methods are implemented as asynchronous JavaScript methods
(even though the underlying protocol exchange might be synchronous in nature).
This means they signal their completion by calling back to the application,
via Success or Failure callback functions provided by the application on the method in question.
Such callbacks are called at most once per method invocation and do not persist beyond the lifetime
of the script that made the invocation.
<p>
In contrast there are some callback functions, most notably <i>onMessageArrived</i>,
that are defined on the <a href="Paho.MQTT.Client.html">Paho.MQTT.Client</a> object.
These may get called multiple times, and aren't directly related to specific method invocations made by the client.
</div>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>host</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            

            

            <td class="description last">the address of the messaging server, as a fully qualified WebSocket URI, as a DNS name or dotted decimal IP address.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>port</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">the port number to connect to - only required if host is not a URI</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>path</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            

            

            <td class="description last">the path on the host to connect to - only used if host is not a URI. Default: '/mqtt'.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>clientId</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            

            

            <td class="description last">the Messaging client identifier, between 1 and 23 characters in length.</td>
        </tr>

    
    </tbody>
</table>






    <h5 class="subsection-title">Properties:</h5>

    

<table class="props">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>host</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            

            

            <td class="description last"><i>read only</i> the server's DNS hostname or dotted decimal IP address.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>port</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last"><i>read only</i> the server's port.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>path</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            

            

            <td class="description last"><i>read only</i> the server's path.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>clientId</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            

            

            <td class="description last"><i>read only</i> used when connecting to the server.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>onConnectionLost</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last">called when a connection has been lost.
                           after a connect() method has succeeded.
                           Establish the call back used when a connection has been lost. The connection may be
                           lost because the client initiates a disconnect or because the server or network
                           cause the client to be disconnected. The disconnect call back may be called without
                           the connectionComplete call back being invoked if, for example the client fails to
                           connect.
                           A single response object parameter is passed to the onConnectionLost callback containing the following fields:
                           <ol>
                           <li>errorCode
                           <li>errorMessage
                           </ol></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>onMessageDelivered</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last">called when a message has been delivered.
                           All processing that this Client will ever do has been completed. So, for example,
                           in the case of a Qos=2 message sent by this client, the PubComp flow has been received from the server
                           and the message has been removed from persistent storage before this callback is invoked.
                           Parameters passed to the onMessageDelivered callback are:
                           <ol>
                           <li><a href="Paho.MQTT.Message.html">Paho.MQTT.Message</a> that was delivered.
                           </ol></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>onMessageArrived</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last">called when a message has arrived in this Paho.MQTT.client.
                           Parameters passed to the onMessageArrived callback are:
                           <ol>
                           <li><a href="Paho.MQTT.Message.html">Paho.MQTT.Message</a> that has arrived.
                           </ol></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>onConnected</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last">called when a connection is successfully made to the server.
                                 after a connect() method.
                                 Parameters passed to the onConnected callback are:
                                 <ol>
                                 <li>reconnect (boolean) - If true, the connection was the result of a reconnect.</li>
                                 <li>URI (string) - The URI used to connect to the server.</li>
                                 </ol></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>disconnectedPublishing</code></td>
            

            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>

            

            

            <td class="description last">if set, will enable disconnected publishing in
                                           in the event that the connection to the server is lost.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>disconnectedBufferSize</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">Used to set the maximum number of messages that the disconnected
                                            buffer will hold before rejecting new messages. Default size: 5000 messages</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>trace</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last">called whenever trace is called. TODO</td>
        </tr>

    
    </tbody>
</table>




<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="paho-mqtt.js.html">paho-mqtt.js</a>, <a href="paho-mqtt.js.html#line1664">line 1664</a>
    </li></ul></dd>
    

    

    

    
</dl>


















    
    </div>

    

    

    

    

    

    

    

    
        <h3 class="subsection-title">Methods</h3>

        
            

    

    
    <h4 class="name" id="connect"><span class="type-signature"></span>connect<span class="signature">(connectOptions)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    Connect this Messaging client to its server.
</div>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>connectOptions</code></td>
            

            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>

            

            

            <td class="description last">Attributes used with the connection.
                <h6>Properties</h6>
                

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>timeout</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">If the connect has not succeeded within this
                   number of seconds, it is deemed to have failed.
                   The default is 30 seconds.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>userName</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            

            

            <td class="description last">Authentication username for this connection.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>password</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            

            

            <td class="description last">Authentication password for this connection.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>willMessage</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="Paho.MQTT.Message.html">Paho.MQTT.Message</a></span>


            
            </td>

            

            

            <td class="description last">sent by the server when the client
                   disconnects abnormally.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>keepAliveInterval</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">the server disconnects this client if
                   there is no activity for this number of seconds.
                   The default value of 60 seconds is assumed if not set.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>cleanSession</code></td>
            

            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>

            

            

            <td class="description last">if true(default) the client and server
                   persistent state is deleted on successful connect.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>useSSL</code></td>
            

            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>

            

            

            <td class="description last">if present and true, use an SSL Websocket connection.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>invocationContext</code></td>
            

            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>

            

            

            <td class="description last">passed to the onSuccess callback or onFailure callback.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>onSuccess</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last">called when the connect acknowledgement
                   has been received from the server.
A single response object parameter is passed to the onSuccess callback containing the following fields:
<ol>
<li>invocationContext as passed in to the onSuccess method in the connectOptions.
</ol></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>onFailure</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last">called when the connect request has failed or timed out.
A single response object parameter is passed to the onFailure callback containing the following fields:
<ol>
<li>invocationContext as passed in to the onFailure method in the connectOptions.
<li>errorCode a number indicating the nature of the error.
<li>errorMessage text describing the error.
</ol></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>hosts</code></td>
            

            <td class="type">
            
                
<span class="param-type">array</span>


            
            </td>

            

            

            <td class="description last">If present this contains either a set of hostnames or fully qualified
WebSocket URIs (ws://mqtt.eclipseprojects.io:80/mqtt), that are tried in order in place
of the host and port paramater on the construtor. The hosts are tried one at at time in order until
one of then succeeds.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>ports</code></td>
            

            <td class="type">
            
                
<span class="param-type">array</span>


            
            </td>

            

            

            <td class="description last">If present the set of ports matching the hosts. If hosts contains URIs, this property
is not used.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>reconnect</code></td>
            

            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>

            

            

            <td class="description last">Sets whether the client will automatically attempt to reconnect
to the server if the connection is lost.
<ul>
<li>If set to false, the client will not attempt to automatically reconnect to the server in the event that the
connection is lost.</li>
<li>If set to true, in the event that the connection is lost, the client will attempt to reconnect to the server.
It will initially wait 1 second before it attempts to reconnect, for every failed reconnect attempt, the delay
will double until it is at 2 minutes at which point the delay will stay at 2 minutes.</li>
</ul></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>mqttVersion</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">The version of MQTT to use to connect to the MQTT Broker.
<ul>
<li>3 - MQTT V3.1</li>
<li>4 - MQTT V3.1.1</li>
</ul></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>mqttVersionExplicit</code></td>
            

            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>

            

            

            <td class="description last">If set to true, will force the connection to use the
selected MQTT Version or will fail to connect.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>uris</code></td>
            

            <td class="type">
            
                
<span class="param-type">array</span>


            
            </td>

            

            

            <td class="description last">If present, should contain a list of fully qualified WebSocket uris
(e.g. ws://mqtt.eclipseprojects.io:80/mqtt), that are tried in order in place of the host and port parameter of the construtor.
The uris are tried one at a time in order until one of them succeeds. Do not use this in conjunction with hosts as
the hosts array will be converted to uris and will overwrite this property.</td>
        </tr>

    
    </tbody>
</table>

            </td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="paho-mqtt.js.html">paho-mqtt.js</a>, <a href="paho-mqtt.js.html#line1845">line 1845</a>
    </li></ul></dd>
    

    

    

    
</dl>











<h5>Throws:</h5>

        

<dl>
    <dt>
        <div class="param-desc">
        If the client is not in disconnected state. The client must have received connectionLost
or disconnected before calling connect for a second or subsequent time.
        </div>
    </dt>
    <dd></dd>
    <dt>
        <dl>
            <dt>
                Type
            </dt>
            <dd>
                
<span class="param-type">InvalidState</span>


            </dd>
        </dl>
    </dt>
    <dd></dd>
</dl>


    







        
            

    

    
    <h4 class="name" id="disconnect"><span class="type-signature"></span>disconnect<span class="signature">()</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    Normal disconnect of this Messaging client from its server.
</div>













<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="paho-mqtt.js.html">paho-mqtt.js</a>, <a href="paho-mqtt.js.html#line2200">line 2200</a>
    </li></ul></dd>
    

    

    

    
</dl>











<h5>Throws:</h5>

        

<dl>
    <dt>
        <div class="param-desc">
        if the client is already disconnected.
        </div>
    </dt>
    <dd></dd>
    <dt>
        <dl>
            <dt>
                Type
            </dt>
            <dd>
                
<span class="param-type">InvalidState</span>


            </dd>
        </dl>
    </dt>
    <dd></dd>
</dl>


    







        
            

    

    
    <h4 class="name" id="getTraceLog"><span class="type-signature"></span>getTraceLog<span class="signature">()</span><span class="type-signature"> &rarr; {Array.&lt;Object>}</span></h4>
    

    



<div class="description">
    Get the contents of the trace log.
</div>













<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="paho-mqtt.js.html">paho-mqtt.js</a>, <a href="paho-mqtt.js.html#line2211">line 2211</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    tracebuffer containing the time ordered trace records.
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Array.&lt;Object></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="publish"><span class="type-signature"></span>publish<span class="signature">(topic, payload, qos, retained)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    Publish a message to the consumers of the destination in the Message.
Synonym for Paho.Mqtt.Client#send
</div>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>topic</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>
|

<span class="param-type"><a href="Paho.MQTT.Message.html">Paho.MQTT.Message</a></span>


            
            </td>

            

            

            <td class="description last"><b>mandatory</b> The name of the topic to which the message is to be published.
					   - If it is the only parameter, used as Paho.MQTT.Message object.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>payload</code></td>
            

            <td class="type">
            
                
<span class="param-type">String</span>
|

<span class="param-type">ArrayBuffer</span>


            
            </td>

            

            

            <td class="description last">The message data to be published.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>qos</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">The Quality of Service used to deliver the message.
		<dl>
			<dt>0 Best effort (default).
    			<dt>1 At least once.
    			<dt>2 Exactly once.
		</dl></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>retained</code></td>
            

            <td class="type">
            
                
<span class="param-type">Boolean</span>


            
            </td>

            

            

            <td class="description last">If true, the message is to be retained by the server and delivered
                    to both current and future subscriptions.
                    If false the server only delivers the message to current subscribers, this is the default for new Messages.
                    A received message has the retained boolean set to true if the message was published
                    with the retained boolean set to true
                    and the subscrption was made after the message has been published.</td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="paho-mqtt.js.html">paho-mqtt.js</a>, <a href="paho-mqtt.js.html#line2148">line 2148</a>
    </li></ul></dd>
    

    

    

    
</dl>











<h5>Throws:</h5>

        

<dl>
    <dt>
        <div class="param-desc">
        if the client is not connected.
        </div>
    </dt>
    <dd></dd>
    <dt>
        <dl>
            <dt>
                Type
            </dt>
            <dd>
                
<span class="param-type">InvalidState</span>


            </dd>
        </dl>
    </dt>
    <dd></dd>
</dl>


    







        
            

    

    
    <h4 class="name" id="send"><span class="type-signature"></span>send<span class="signature">(topic, payload, qos, retained)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    Send a message to the consumers of the destination in the Message.
</div>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>topic</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>
|

<span class="param-type"><a href="Paho.MQTT.Message.html">Paho.MQTT.Message</a></span>


            
            </td>

            

            

            <td class="description last"><b>mandatory</b> The name of the destination to which the message is to be sent.
					   - If it is the only parameter, used as Paho.MQTT.Message object.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>payload</code></td>
            

            <td class="type">
            
                
<span class="param-type">String</span>
|

<span class="param-type">ArrayBuffer</span>


            
            </td>

            

            

            <td class="description last">The message data to be sent.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>qos</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">The Quality of Service used to deliver the message.
		<dl>
			<dt>0 Best effort (default).
    			<dt>1 At least once.
    			<dt>2 Exactly once.
		</dl></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>retained</code></td>
            

            <td class="type">
            
                
<span class="param-type">Boolean</span>


            
            </td>

            

            

            <td class="description last">If true, the message is to be retained by the server and delivered
                    to both current and future subscriptions.
                    If false the server only delivers the message to current subscribers, this is the default for new Messages.
                    A received message has the retained boolean set to true if the message was published
                    with the retained boolean set to true
                    and the subscrption was made after the message has been published.</td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="paho-mqtt.js.html">paho-mqtt.js</a>, <a href="paho-mqtt.js.html#line2098">line 2098</a>
    </li></ul></dd>
    

    

    

    
</dl>











<h5>Throws:</h5>

        

<dl>
    <dt>
        <div class="param-desc">
        if the client is not connected.
        </div>
    </dt>
    <dd></dd>
    <dt>
        <dl>
            <dt>
                Type
            </dt>
            <dd>
                
<span class="param-type">InvalidState</span>


            </dd>
        </dl>
    </dt>
    <dd></dd>
</dl>


    







        
            

    

    
    <h4 class="name" id="startTrace"><span class="type-signature"></span>startTrace<span class="signature">()</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    Start tracing.
</div>













<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="paho-mqtt.js.html">paho-mqtt.js</a>, <a href="paho-mqtt.js.html#line2222">line 2222</a>
    </li></ul></dd>
    

    

    

    
</dl>


















        
            

    

    
    <h4 class="name" id="stopTrace"><span class="type-signature"></span>stopTrace<span class="signature">()</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    Stop tracing.
</div>













<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="paho-mqtt.js.html">paho-mqtt.js</a>, <a href="paho-mqtt.js.html#line2232">line 2232</a>
    </li></ul></dd>
    

    

    

    
</dl>


















        
            

    

    
    <h4 class="name" id="subscribe"><span class="type-signature"></span>subscribe<span class="signature">(filter, subscribeOptions)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    Subscribe for messages, request receipt of a copy of messages sent to the destinations described by the filter.
</div>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>filter</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            

            

            <td class="description last">describing the destinations to receive messages from.
<br></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>subscribeOptions</code></td>
            

            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>

            

            

            <td class="description last">used to control the subscription
                <h6>Properties</h6>
                

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>qos</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">the maiximum qos of any publications sent
                                 as a result of making this subscription.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>invocationContext</code></td>
            

            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>

            

            

            <td class="description last">passed to the onSuccess callback
                                 or onFailure callback.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>onSuccess</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last">called when the subscribe acknowledgement
                                 has been received from the server.
                                 A single response object parameter is passed to the onSuccess callback containing the following fields:
                                 <ol>
                                 <li>invocationContext if set in the subscribeOptions.
                                 </ol></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>onFailure</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last">called when the subscribe request has failed or timed out.
                                 A single response object parameter is passed to the onFailure callback containing the following fields:
                                 <ol>
                                 <li>invocationContext - if set in the subscribeOptions.
                                 <li>errorCode - a number indicating the nature of the error.
                                 <li>errorMessage - text describing the error.
                                 </ol></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>timeout</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">which, if present, determines the number of
                                 seconds after which the onFailure calback is called.
                                 The presence of a timeout does not prevent the onSuccess
                                 callback from being called when the subscribe completes.</td>
        </tr>

    
    </tbody>
</table>

            </td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="paho-mqtt.js.html">paho-mqtt.js</a>, <a href="paho-mqtt.js.html#line2007">line 2007</a>
    </li></ul></dd>
    

    

    

    
</dl>











<h5>Throws:</h5>

        

<dl>
    <dt>
        <div class="param-desc">
        if the client is not in connected state.
        </div>
    </dt>
    <dd></dd>
    <dt>
        <dl>
            <dt>
                Type
            </dt>
            <dd>
                
<span class="param-type">InvalidState</span>


            </dd>
        </dl>
    </dt>
    <dd></dd>
</dl>


    







        
            

    

    
    <h4 class="name" id="unsubscribe"><span class="type-signature"></span>unsubscribe<span class="signature">(filter, unsubscribeOptions)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    Unsubscribe for messages, stop receiving messages sent to destinations described by the filter.
</div>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>filter</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            

            

            <td class="description last">describing the destinations to receive messages from.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>unsubscribeOptions</code></td>
            

            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>

            

            

            <td class="description last">used to control the subscription
                <h6>Properties</h6>
                

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>invocationContext</code></td>
            

            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>

            

            

            <td class="description last">passed to the onSuccess callback
		                                      or onFailure callback.</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>onSuccess</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last">called when the unsubscribe acknowledgement has been received from the server.
                                   A single response object parameter is passed to the
                                   onSuccess callback containing the following fields:
                                   <ol>
                                   <li>invocationContext - if set in the unsubscribeOptions.
                                   </ol></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>onFailure</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last">called when the unsubscribe request has failed or timed out.
                                   A single response object parameter is passed to the onFailure callback containing the following fields:
                                   <ol>
                                   <li>invocationContext - if set in the unsubscribeOptions.
                                   <li>errorCode - a number indicating the nature of the error.
                                   <li>errorMessage - text describing the error.
                                   </ol></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>timeout</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">which, if present, determines the number of seconds
                                   after which the onFailure callback is called. The presence of
                                   a timeout does not prevent the onSuccess callback from being
                                   called when the unsubscribe completes</td>
        </tr>

    
    </tbody>
</table>

            </td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="paho-mqtt.js.html">paho-mqtt.js</a>, <a href="paho-mqtt.js.html#line2056">line 2056</a>
    </li></ul></dd>
    

    

    

    
</dl>











<h5>Throws:</h5>

        

<dl>
    <dt>
        <div class="param-desc">
        if the client is not in connected state.
        </div>
    </dt>
    <dd></dd>
    <dt>
        <dl>
            <dt>
                Type
            </dt>
            <dd>
                
<span class="param-type">InvalidState</span>


            </dd>
        </dl>
    </dt>
    <dd></dd>
</dl>


    







        
    

    

    
</article>

</section>




</div>

<nav>
    <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Paho.MQTT.Client.html">Client</a></li><li><a href="Paho.MQTT.Message.html">Message</a></li></ul><h3>Namespaces</h3><ul><li><a href="Paho.MQTT.html">MQTT</a></li></ul>
</nav>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.3</a> on Fri Aug 04 2017 09:22:59 GMT+0100 (BST)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
